<template>
  <div>
    <a-upload
      v-model:file-list="fileList"
      name="file"
      :multiple="true"
      action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
      :headers="headers"
      @change="handleChange"
    >
      <a-button>
        <upload-outlined></upload-outlined>
        Click to Upload
      </a-button>
    </a-upload>
  </div>
</template>

<script setup lang="ts">
  // Import statements
  import { ref, computed, onMounted } from 'vue'
  import { ElMessage } from 'element-plus'

  interface FileItem {
    uid: string
    name?: string
    status?: string
    response?: string
    url?: string
  }

  interface FileInfo {
    file: FileItem
    fileList: FileItem[]
  }

  const handleChange = (info: FileInfo) => {
    if (info.file.status !== 'uploading') {
      console.log(info.file, info.fileList)
    }
    if (info.file.status === 'done') {
      ElMessage.success(`${info.file.name} file uploaded successfully`)
    } else if (info.file.status === 'error') {
      ElMessage.error(`${info.file.name} file upload failed.`)
    }
  }

  const fileList = ref([])
</script>

<style scoped>
  .container {
    padding: 1rem;
  }
</style>
